package lib;

import js.html.*;

@:native("THREE")
extern class THREE {
	/**
	 * 版本号
	 */
	public static var REVISION;
}

@:native("THREE.Scene")
extern class Scene {
	function new():Void;

	/**
	 * 添加物体到场景
	 * @param obj
	 */
	function add(obj:Dynamic):Void;
}

@:native("THREE.Camera")
extern class Camera {
	/**
	 * 位置
	 */
	var position:Vector3;

	/**
	 * 朝向
	 * @param vector
	 */
	function lookAt(vector:Vector3):Void;

	/**
	 * 创建摄像头
	 * @param fov
	 * @param aspect
	 * @param near
	 * @param far
	 */
	function new(?fov:Float, ?aspect:Float, ?near:Float, ?far:Float):Void;
}

@:native("THREE.PerspectiveCamera")
extern class PerspectiveCamera extends Camera {}

@:native("THREE.BoxBufferGeometry")
extern class BoxBufferGeometry extends Geometry {
	function new(?width:Float, ?height:Float, ?depth:Float, ?widthSegments:Float, ?heightSegments:Int, ?depthSegments:Float):Void;
}

@:native("THREE.MeshBasicMaterial")
extern class MeshBasicMaterial extends Material {
	// var color:Color;
	// var map:Texture;
	// var aoMap:Texture;
	// var aoMapIntensity:Float;
	// var specularMap:Texture;
	// var alphaMap:Texture;
	// var envMap:Texture;
	// var combine:Combine;
	// var reflectivity:Float;
	// var refractionRatio:Float;
	// // var shading : Shading;
	// var wireframe:Bool;
	// var wireframeLinewidth:Float;
	// var wireframeLinecap:String;
	// var wireframeLinejoin:String;
	// var skinning:Bool;
	// var morphTargets:Bool;

	/**
	 * 材质
	 * @param opt 设置
	 */
	function new(?opt:Dynamic):Void;
}

@:native("THREE.Mesh")
extern class Mesh {
	/**
	 * 位置
	 */
	var position:Vector3;

	/**
	 * 旋转
	 */
	var rotation:Vector3;
	function new(?geometry:Geometry, ?material:Material):Void;
}

@:native("THREE.Vector3")
extern class Vector3 {
	/**
	 * x坐标
	 */
	var x:Float;

	/**
	 * y坐标
	 */
	var y:Float;

	/**
	 * z坐标
	 */
	var z:Float;
	function new(?x:Float, ?y:Float, ?z:Float):Void;
	function set(x:Float, y:Float, z:Float):Vector3;
}

@:native("THREE.Geometry")
extern class Geometry {
	function new():Void;
}

@:native("THREE.Material")
extern class Material {
	function new():Void;
}

extern interface RenderTarget {}

@:native("THREE.WebGLRenderer")
extern class WebGLRenderer {
	function new(?opt:Dynamic):Void;
	var domElement:CanvasElement;
	function getContext():js.html.webgl.RenderingContext;
	function getContextAttributes():Dynamic;
	function forceContextLoss():Void;
	function getMaxAnisotropy():Int;
	function getPrecision():String;
	function getPixelRatio():Float;
	/**
	 * 设置设备像素比。通常用于HiDPI设备防止模糊输出canvas。
	 * @param value 
	 */
	function setPixelRatio(value:Float):Void;
	function getSize():{var width:Float; var height:Float;};
	function setSize(width:Float, height:Float, ?updateStyle:Bool):Void;
	function setViewport(?x:Float, ?y:Float, ?width:Float, ?height:Float):Void;
	function setScissor(x:Float, y:Float, width:Float, height:Float):Void;
	function setScissorTest(enable:Bool):Void;
	function render(scene:Scene, camera:Camera, ?renderTarget:RenderTarget, ?forceClear:Bool):Void;
}

@:native("THREE.TextureLoader")
extern class TextureLoader {
	function new():Void;
	function load(url:String, ?onLoad:Texture->Void, ?onProgress:ProgressEvent->Void, ?onError:ErrorEvent->Void):Texture;
	function setCrossOrigin(crossOrigin:String):TextureLoader;
	function setWithCredentials(value:String):TextureLoader;
	function setPath(path:String):TextureLoader;
}

@:native("THREE.Texture")
extern class Texture {}

class Embed {
	inline public function __init__() {
		haxe.macro.Compiler.includeFile("three.js");
	}
}
